package com.yanqu.road.dao.impl.activity.zhounianturntable;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.zhounianturntable.ZhouNianTurntableConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ZhouNianTurntableConfigDaoImpl extends TempDao {

    public Map<Integer, ZhouNianTurntableConfig> getZhouNianTurntableConfigMap(Integer activityId) {
        String sql = "select * from `t_s_activity_zhounian_turntable` where activityId = ? ";
        Map<Integer, ZhouNianTurntableConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                ZhouNianTurntableConfig turntableConfig = new ZhouNianTurntableConfig();
                turntableConfig.setActivityId(rs.getInt("activityId"));
                turntableConfig.setGear(rs.getInt("gear"));
                turntableConfig.setReward(rs.getString("reward"));
                turntableConfig.setScore(rs.getInt("score"));
                turntableConfig.setSelectNum(rs.getInt("selectNum"));
                turntableConfig.setWeight(rs.getInt("weight"));
                turntableConfig.setAnnounce(rs.getInt("announce"));
                map.put(turntableConfig.getGear(), turntableConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

}
